<template>
  <view class="video">
    <!-- 标签栏 -->
    <view class="video-tab">
      <!-- 标签栏标题 -->
      <view class="video-tab-title">
        <!-- uniSegmentedControl是uni-ui的分段器（标签栏）组件 -->
        <uni-segmented-control :current="current"
          :values="items.map(v=>v.title)" @clickItem="onClickItem"
          style-type="text" active-color="#d4237a">
        </uni-segmented-control>
      </view>
      <!-- 右侧搜索图标 -->
      <view class="iconfont iconsearch"></view>
    </view>
    <view class="video-content">
      <video-main v-if="current < 4" :requestObj="items[current]"></video-main>
      <video-category v-if="current === 4" :requestObj="items[4]">
      </video-category>
    </view>
  </view>
</template>

<script>
import { uniSegmentedControl } from '@dcloudio/uni-ui'
import videoMain from './VideoMain'
import videoCategory from './VideoCategory'
export default {
  data() {
    return {
      items: [
        {
          title: '推荐',
          url: 'http://157.122.54.189:9088/videoimg/v1/videowp/featured',
          params: { limit: 30, skip: 0, order: 'hot' }
        },
        {
          title: '娱乐',
          url:
            'http://157.122.54.189:9088/videoimg/v1/videowp/category/59b25abbe7bce76bc834198a',
          params: { limit: 30, skip: 0, order: 'new' }
        },
        {
          title: '最新',
          url: 'http://157.122.54.189:9088/videoimg/v1/videowp/videowp',
          params: { limit: 30, skip: 0, order: 'new' }
        },
        {
          title: '热门',
          url: 'http://157.122.54.189:9088/videoimg/v1/videowp/videowp',
          params: { limit: 30, skip: 0, order: 'hot' }
        },
        {
          title: '分类',
          url: 'http://157.122.54.189:9088/videoimg/v1/videowp/category'
        }
      ],
      current: 0
    }
  },
  components: {
    uniSegmentedControl,
    videoMain,
    videoCategory
  },
  methods: {
    // 根据被点击的标题，切换标题
    onClickItem(e) {
      if (this.current !== e.currentIndex) {
        this.current = e.currentIndex
      }
    }
  }
}
</script>

<style lang='scss' scoped>
.video-tab {
  position: relative;
  box-shadow: 0 3rpx 10rpx 2rpx rgba(100, 100, 100, 0.2);
  z-index: 1;
  .video-tab-title {
    width: 60%;
    margin: 0 auto;
  }
  .iconsearch {
    position: absolute;
    top: 50%;
    right: 5%;
    transform: translateY(-50%);
  }
}
</style>